home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
MINHLP.ZIP
/
MH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-04
|
40KB
|
1,437 lines
// Printout is in \foo.c
// Still need to create .PRJ file.
// Doesn't handle text containing { or }.
// All calls to Parse() need error checking.
// Check header documentation, such as "To compile" note.
// Search for this:
// puts("XXX Error--Improve this error handling!");
// Search for all XXX occurrences, which represent code to improve.
// Maybe a feature that creates an index or table of contents?
// Ask on WINSDK
// - How to specify bold or italic?
// - What's the max length of a line in HC.EXE?
// - How do you create a table of contents?
/* ==========================================================
File: MH.C -- MiniHelp
What it is: Simplifies the creation of help topic files
by converting dot commands to RTF.
Also eliminates the need for an RTF editor
when creating simple help files.
Compiler: ANSI C
By: Tom Campbell
Notes:
To compile: Link with
Example using Borland C:
bcc mh.c
Example using Microsoft C:
cl mh.c
To test:
To run:
Copyright 1993 by Tom Campbell. All rights reserved.
========================================================== */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* ==========================================================
TYPE DECLARATIONS
========================================================== */
typedef int BOOL;
typedef unsigned WORD;
/* ==========================================================
FUNCTION DECLARATIONS
========================================================== */
void AddExtension(char *str, char *ext);
int CreateHelpFromMetascript(char *InFilename,
char *OutFilename, BOOL MakeTopicKeyword);
void CreateKeyword(FILE *OutFile, char *Keyword, int Line);
void CreateTitle(FILE *OutFile, char *Title, int Line);
void Error(int Line, char *Msg);
int HasExtension(char *Filename);
int Parse(char *Input, char *Separators, WORD StartAt,
BOOL ForceUpper, WORD MaxLen,
char *Buffer);
int PossibleLinkInLine(FILE *OutFile, char *NextLine,
WORD StartAt, int LineNo);
void Quit(char *Msg, int ErrorLevel);
void ReplaceExtension(char *Filename, char *Ext);
int StripExtension(char *input);
int UpStr(char *Str);
void WriteChars(FILE *OutFile, char *Line, int Count,
int LineNo);
void WriteLine(FILE *OutFile, char *Line, int LineNo);
/* ==========================================================
CONSTANTS
========================================================== */
#define FALSE 0
#define TRUE (!FALSE)
#define MAX_LINE 500
#define MAX_FILENAME 140
/* ==========================================================
AddExtension()
========================================================== */
void AddExtension(char *str, char *ext)
/* ==========================================================
What it does:
Adds the ext to str if str doesn't already have an extension.
A period by itself counts as an extension.
Samples:
AddExtension("foobar", "bak") == "foobar.bak"
AddExtension("combat.", "lib") == "combat."
AddExtension("vid.obj", ".bak"). == "vid.obj"
Parameters:
str : Filename w/out extension.
ext : Desired extension.
Returns:
TRUE on success.
FALSE on failure.
Before calling:
The file must be opened with dbfUse().
Standard #include files required:
string.h
See also:
HasExtension(), ReplaceExtension()
Example:
char request[80], response[80];
printf("\n\nTesting AddExtension(). Please enter a string or \"q\" to quit. ");
gets(request);
printf("\nAdd what extension? ");
gets(response);
AddExtension(request, response);
printf("\nResult: \"%s\"", request);
Copyright 1992 by Tom Campbell. All rights reserved.
======================================================== */
{
char *index;
index = strchr(str, '.'); /* Is there a period in the filename? */
if (index == NULL) { /* No. It's safe to add an extension. */
str = strcat(str, "."); /* Append a period, */
str = strcat(str, ext); /* then then extension. */
}
else { /* Yes, there was an extension. Write over */
/* str = str + (index-str); */
strcpy(++index, ext);
}
} /* AddExtension() */
/* ========================================================== */
void Error(int Line, char *Msg)
/* ========================================================== */
/* ==========================================================
What it does:
Displays the line number and the provided error message.
If the line number is 0, doesn't print it (used in a
case where it's irrelevant, such as not being able to
create the output file).
Parameters:
Line : Line number error occurred on.
Msg : Text of error message.
Copyright 1993 by Tom Campbell. All rights reserved.
======================================================== */
{
if (Error)
printf("Error on line %d: %s\n", Line, Msg);
else
printf("Error: %s\n", Msg);
} /* Error() */
/* ========================================================== */
int HasExtension(char *Filename)
/* ========================================================== */
/* ==========================================================
What it does:
Determines whether the specified DOS filename has an
extension.
Parameters:
*Filename : File specification, possibly with an
extension.
Returns:
Character position in array of extension if present.
0 if not.
Copyright 1993 by Tom Campbell. All rights reserved.
======================================================== */
{
int LastPossible, Length;
Length = strlen(Filename);
if (Length < 2)
return 0;
LastPossible = Length-1;
while(LastPossible) {
if (Filename[LastPossible] == '.')
return LastPossible;
else
LastPossible--;
}
return 0;
} /* HasExtension() */
/* ==========================================================
Parse()
========================================================== */
int Parse(char *Input, char *Separators, WORD StartAt,
BOOL ForceUpper, WORD MaxLen,
char *Buffer)
/* ==========================================================
What it does:
Copies the next word or token or whatever from Input and
copies it into Buffer.
Parameters:
Input : String to be separators into tokens.
Separators : Characters to be used as token delimiters.
StartAt : Index of character at which to start parsing.
ForceUpper : If TRUE, forces the output (which is copied
to Buffer) to uppercase.
MaxLen : Maximum # of chars to be copied into Buffer.
Buffer : Buffer at least MaxLen chars wide to hold the
output.
Returns:
Character position in string after the routine
was called.
0 if had to return due to error condition, such as a
separator or input string of length 0.
Standard #include files required:
string.h
ctype.h
Example:
void main(void)
{
#define MAX_LEN 100
int EndedAt;
char Input[MAX_LEN];
int Len;
char Separators[MAX_LEN];
WORD StartAt = 0;
BOOL ForceUpper = FALSE;
WORD MaxLen = MAX_LEN;
#define MAX_TOKEN 5
char Buffer[MAX_TOKEN + 1];
do {
Input[0] = '\0';
printf("String to parse: ");
gets(Input);
if (Input[0]) {
printf("Separators: ");